// pages/team/team.js
const {
  req
} = require('../../utils/requests')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    teamInfo: [], //基本信息
    nTeamDetails: [], //基本数据
    communityInfo: [],
    baseInfo: [], //阵容数据
    titleName: '',
    matchesList: [], //比赛赛程
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let self = this
    this.setData({
      id: options.playid
    })
    
    this.init()
  },
  init() {
    let self = this
    // 页面初始数据、荣誉等
    req('https://matchweb.sports.qq.com/teamUtil/teamInfo?from=h5&competitionId=100000&teamId=' + self.data.id + '&usage=').then(res => {
      self.setData({
        teamInfo: res.data.data
      })
    })

    // 球队常规、进阶、赛季最高等数据
    req('https://matchweb.sports.qq.com/teamUtil/nTeamDetails?from=h5&teamId=' + self.data.id + '&competitionId=100000&seasonId=2022&seasonType=playoff').then(res => {
      self.setData({
        nTeamDetails: res.data.data
      })
    })

    // 顶部信息、以及相关 数据
    req('https://matchweb.sports.qq.com/teamUtil/teamHeader?from=h5&competitionId=100000&teamId=' + self.data.id + '&backflow=undefined&os=ios&hideSalary=true&hideInfo=true').then(res => {
      self.setData({
        communityInfo: res.data.data,
      })
    })

    // 获取阵容
    req('https://matchweb.sports.qq.com/teamUtil/teamLineup?from=h5&competitionId=100000&teamId=' + self.data.id).then(res => {
      self.setData({
        baseInfo: res.data.data
      })
    })
    // 获取赛程
    req('https://app.sports.qq.com/match/list?columnId=100000&appvid=&teamId=' + self.data.id).then(res => {
      self.setData({
        matchesList: res.data.data
      })
    })
    // 获取动态。

  },
  // 跳转到比赛详情界面
  gotoRaceDetails(e) {
    let mid = e.currentTarget.dataset.item.mid
    wx.redirectTo({
      url: '../raceDetails/raceDetails?mid=' + JSON.stringify(mid)
    })
  },
  // 跳转到球员详情界面
  gotoplayerId(e) {
    let playerId = e.currentTarget.dataset.playerid.playerId
    wx.redirectTo({
      url: '../playerInformation/playerInformation?playid=' + JSON.stringify(playerId)
    })
  }

})